# import requests
#
# url = 'https://api.web.360kan.com/v1/rank?cat=1&callback=__jp0'
#
# r = requests.get(url)
# content = r.text[6:-2]
# print(content)
# print(r.status_code)


import asyncio
import aiohttp

async def fetch(session,url):
    async with session.get(url) as response:
        response = await response.json()
        print(response)



async def main():
    async with aiohttp.ClientSession() as session:
        await asyncio.gather(*[fetch(session,f'https://api.web.360kan.com/v1/rank?cat={t}') for t in range(1, 7)])

asyncio.run(main())




# https://api.web.360kan.com/v1/rank?cat=1&callback=__jp30
# import requests
# urls = [f'https://api.web.360kan.com/v1/rank?cat={t}' for t in range(1, 7)]
# for url in urls:
#     response = requests.get(url)
#     print(response.json())




# import asyncio
# import aiohttp
#
#
# async def fetch(session, url):
#     async with session.get(url) as response:
#         response = await response.json()
#         return response
#
# async def main():
#     async with aiohttp.ClientSession() as session:
#         urls = [f'https://api.web.360kan.com/v1/rank?cat={t}' for t in range(1, 7)]
#         tasks = [fetch(session, url) for url in urls]
#         datas = await asyncio.gather(*tasks)
#         for data in datas:
#             print(data)
# asyncio.run(main())




import threading
import time
import requests

def t_main(url):
    time.sleep(1)
    response = requests.get(url)
    print(f"线程{threading.current_thread().name}获取到数据", response.json())

def main():
    print(f"主线程开始执行")
    urls = [f'https://api.web.360kan.com/v1/rank?cat={t}' for t in range(1, 7)]
    threads = []
    for url in urls:
        t = threading.Thread(target=t_main, name=f'thread-{url}', args=(url,))
        threads.append(t)
        t.start()
    for t in threads:
        t.join()
    print(f"主线程结束了")


if __name__ == '__main__':
    main()


